#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QStackedWidget>

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    buttonGroup = new QButtonGroup();
    for(int i = 0;i < 10;i ++)
        buttonGroup->addButton(new QPushButton(this),i);
    for(int i = 0;i < 10;i ++)
    {
        buttonGroup->button(i)->setText(QString::number(i));
        buttonGroup->button(i)->resize(60,30);
        buttonGroup->button(i)->move(10,10 + i * 30);
        buttonGroup->button(i)->show();
    }
    connect(buttonGroup,SIGNAL(buttonClicked(int)),ui->stackedWidget,SLOT(setCurrentIndex(int)));

    QTimer *time = new QTimer();
    connect(time,&QTimer::timeout,this,[=](){
        ui->widget->clearSeries();

        QList<QPointF> buff;
        for(int i = 0;i < 10;i ++)
           buff.append(QPointF(i,qrand()%100));

        QList<QPointF> buff2;
        for(int i = 0;i < 10;i ++)
           buff2.append(QPointF(i,qrand()%100));

        ui->widget->setChartTitle("测试坐标系");
        ui->widget->addSeres(buff,"line1");
        ui->widget->addSeres(buff2,"line2");
    });
    time->start(1000);
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::on_pushButton_clicked()
{
    MyChart *wid = new MyChart();
    QList<QPointF> buff;
    for(int i = 0;i < 10;i ++)
       buff.append(QPointF(i,qrand()%100));

    QList<QPointF> buff2;
    for(int i = 0;i < 10;i ++)
       buff2.append(QPointF(i,qrand()%100));
    wid->addSeres(buff,"line1");
    wid->addSeres(buff2,"line2");
    wid->show();
}
